package com.video.main_video.manager.handle.videoInfo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.video.main_video.api.Api;
import com.video.main_video.common.jwt.JwtUtils;
import com.video.main_video.dao.entity.VideoInfo;
import com.video.main_video.dao.request.videoInfo.VideoGetRequest;
import com.video.main_video.dao.response.videoInfo.VideoInfoGetResponse;
import com.video.main_video.manager.handle.ApiHandler;
import com.video.main_video.manager.mapper.VideoInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;


@Api
public class VideoGetManager implements ApiHandler<VideoGetRequest, VideoInfoGetResponse> {

    @Autowired
    VideoInfoMapper videoInfoMapper;

    @Override
    public VideoInfoGetResponse handler(VideoGetRequest videoGetRequest) {
        VideoInfoGetResponse res = getVideoInfo(videoGetRequest);
        return res;
    }

    private VideoInfoGetResponse getVideoInfo(VideoGetRequest req){
        LambdaQueryWrapper<VideoInfo> qw = new LambdaQueryWrapper<VideoInfo>();
        qw.eq(VideoInfo::getCutId,req.getCutId());
        VideoInfo info = videoInfoMapper.selectOne(qw);
        VideoInfoGetResponse res=new VideoInfoGetResponse();
        res.setCode(200);
        if (null==info){
            return res;
        }
        res.setAuthor("wdx");
        res.setVideoName(info.getVideoName());
        res.setCategory(info.getVideoCategory());

        Map<String,String> map=new HashMap<>();
        map.put("videoName",info.getVideoName());
        map.put("path",info.getVideoDir());

        String token = JwtUtils.getToken(map);

        res.setVideoSrc(token);

        return res;

    }


}
